<template>
  <view class="game-space-container">
    <!-- 页面头部 -->
    <view class="page-header">
      <view class="header-title-container">
        <i class="header-icon fas fa-gamepad"></i>
        <view>
          <h1 class="header-title">游戏空间</h1>
          <p class="header-subtitle">探索精彩游戏世界</p>
        </view>
      </view>
    </view>

    <!-- 游戏列表 -->
    <view class="games-grid">
      <view class="game-card" @tap="navigateToGame('snake')">
        <view class="game-icon bg-green-100 text-green-500">
          <i class="fa fa-gamepad text-4xl"></i>
        </view>
        <view class="game-info">
          <view class="game-name font-bold">贪吃蛇</view>
          <view class="game-online text-xs text-gray-500">在线 0 人</view>
        </view>
      </view>

      <view class="game-card" @tap="navigateToGame('gomoku')">
        <view class="game-icon bg-blue-100 text-blue-500">
          <i class="fa fa-gamepad text-4xl"></i>
        </view>
        <view class="game-info">
          <view class="game-name font-bold">五子棋</view>
          <view class="game-online text-xs text-gray-500">在线 0 人</view>
        </view>
      </view>

      <view class="game-card" @tap="navigateToGame('tictactoe')">
        <view class="game-icon bg-yellow-100 text-yellow-500">
          <i class="fa fa-gamepad text-4xl"></i>
        </view>
        <view class="game-info">
          <view class="game-name font-bold">井字棋</view>
          <view class="game-online text-xs text-gray-500">在线 0 人</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { useRouter } from 'vue-router';

const router = useRouter();

/**
 * 导航到指定游戏
 * @param {string} gameName - 游戏名称
 */
function navigateToGame(gameName) {
  // 这里只是示例，实际应该根据游戏名称导航到对应的页面
  router.push(`/pages/games/${gameName}/${gameName}`);
}
</script>

<style scoped>
.game-space-container {
  padding: 20px;
  min-height: 100vh;
  background-color: #f5f7fa;
}

.page-header {
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}

.header-title-container {
  display: flex;
  align-items: center;
}

.header-icon {
  font-size: 28px;
  color: #4096ff;
  margin-right: 12px;
  transition: transform 0.3s ease;
}

.header-title-container:hover .header-icon {
  transform: rotate(15deg);
}

.header-title {
  font-size: 24px;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 4px 0;
}

.header-subtitle {
  font-size: 14px;
  color: #64748b;
  margin: 0;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 24px;
}

.game-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.game-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.game-card:nth-child(1)::before { background-color: #10b981; }
.game-card:nth-child(2)::before { background-color: #3b82f6; }
.game-card:nth-child(3)::before { background-color: #f59e0b; }

.game-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.05);
}

.game-card:hover::before {
  opacity: 1;
}

.game-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  transition: transform 0.3s ease;
}

.game-card:hover .game-icon {
  transform: scale(1.1);
}

.game-icon.bg-green-100 {
  background-color: #ecfdf5;
}

.game-icon.bg-blue-100 {
  background-color: #eff6ff;
}

.game-icon.bg-yellow-100 {
  background-color: #fef3c7;
}

.game-info {
  text-align: center;
  width: 100%;
}

.game-name {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 8px;
  transition: color 0.3s ease;
}

.game-card:hover .game-name {
  color: #4096ff;
}

.game-online {
  font-size: 13px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
}

.game-online::before {
  content: '●';
  font-size: 8px;
  margin-right: 6px;
  color: #10b981;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.4; }
  100% { opacity: 1; }
}

/* Empty state styles */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: #64748b;
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 20px;
  color: #d1d5db;
  transition: transform 0.3s ease;
}

.empty-state:hover .empty-state-icon {
  transform: rotate(-10deg) scale(1.1);
}

.empty-state p {
  margin-bottom: 24px;
  font-size: 16px;
}

.empty-state button {
  padding: 10px 20px;
  background-color: #4096ff;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s ease;
}

.empty-state button:hover {
  background-color: #3182ce;
  transform: translateY(-2px);
}
</style>